package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.common.util.UserUtil;
import com.lzy.product.dao.ProductClassifyMapperExt;
import com.lzy.product.dtos.ProductClassifyDto;
import com.lzy.product.entity.ProductClassify;
import com.lzy.product.service.ProductClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2017/11/28.
 */
@Service
public class ProductClassifyServiceImpl implements ProductClassifyService {
    @Autowired
    ProductClassifyMapperExt productClassifyMapperExt;

    @Override
    public Long insert(ProductClassifyDto dto) {
        ProductClassify productInfo = DozerUtils.map(dto, ProductClassify.class);
        return productClassifyMapperExt.insertSelective(productInfo) > 0 ? productInfo.getId() : null;
    }

    @Override
    public Boolean update(ProductClassifyDto dto) {
        return productClassifyMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, ProductClassify.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return productClassifyMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        return productClassifyMapperExt.remove(id, UserUtil.getCurrentUser().getId()) > 0;
    }

    @Override
    public ProductClassifyDto findById(Long id) {
        return DozerUtils.map(productClassifyMapperExt.selectByPrimaryKey(id), ProductClassifyDto.class);
    }

    @Override
    public List<ProductClassifyDto> query(ProductClassifyDto dto) {
        return productClassifyMapperExt.selectList(dto);
    }

    @Override
    public PageInfo<ProductClassifyDto> selectList(Pager pager, ProductClassifyDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ProductClassifyDto> productClassifyDtoList = productClassifyMapperExt.selectList(dto);
        return new PageInfo<>(productClassifyDtoList);
    }

    @Override
    public Integer removeList(String ids) {
        return productClassifyMapperExt.removeList(ids, UserUtil.getCurrentUser().getId());
    }

    @Override
    public Boolean updateShelves(Integer shelves, String ids) {
        return productClassifyMapperExt.updateShelves(shelves,ids)>0;
    }
}
